From b0bfeeabaddecc914d818482d994b49ccc786b11 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sun, 18 Sep 2005 21:08:17 +0000 Subject: [PATCH] Added BablFishPath introspecters, moved logic out of rest into bablcore --- tests/Makefile.am | 18 +- tests/babl-html-dump.c | 8 +- tests/babl_fish_path_dhtml.c | 328 +++++++++++++++++++++++++++++++++ tests/babl_fish_path_fitness.c | 95 ++++++++++ tests/conversions.c | 138 +------------- tests/formats.c | 66 +------ tests/models.c | 157 +--------------- tests/types.c | 92 +-------- 8 files changed, 457 insertions(+), 445 deletions(-) create mode 100644 tests/babl_fish_path_dhtml.c create mode 100644 tests/babl_fish_path_fitness.c diff --git a/tests/Makefile.am b/tests/Makefile.am index c0910e9..0b07eda 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -10,10 +10,8 @@ TESTS = \ srgb_to_lab_u8 \ sanity \ babl_class_name \ - conversions \ types \ - models \ - formats + models TESTS_ENVIRONMENT = BABL_PATH=$(top_builddir)/extensions @@ -24,6 +22,8 @@ rgb_to_ycbcr_SOURCES = rgb_to_ycbcr.c babl_class_name_SOURCES = babl_class_name.c sanity_SOURCES = sanity.c types_SOURCES = types.c +babl_fish_path_fitness_SOURCES = babl_fish_path_fitness.c +babl_fish_path_dhtml_SOURCES = babl_fish_path_dhtml.c formats_SOURCES = formats.c models_SOURCES = models.c @@ -32,10 +32,14 @@ AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl LDADD = $(top_builddir)/babl/libbabl.la -lm ${dl} -noinst_PROGRAMS = \ - introspect \ - babl_html_dump \ - nop \ +noinst_PROGRAMS = \ + introspect \ + babl_fish_path_fitness \ + babl_fish_path_dhtml \ + babl_html_dump \ + conversions \ + formats \ + nop \ $(TESTS) introspect_SOURCES = introspect.c diff --git a/tests/babl-html-dump.c b/tests/babl-html-dump.c index eb2e8e7..55c95cd 100644 --- a/tests/babl-html-dump.c +++ b/tests/babl-html-dump.c @@ -42,7 +42,7 @@ main (void) babl_type_each (show_item, NULL); babl_model_each (show_item, NULL); babl_format_each (show_item, NULL); - babl_conversion_each (show_item, NULL); +/* babl_conversion_each (show_item, NULL);*/ printf ("'>+"); printf ("-"); printf ("
"); @@ -72,13 +72,13 @@ main (void) printf ("
\n"); printf ("\n"); - +/* printf ("
"); printf ("
\n"); babl_conversion_each (each_item, NULL); printf ("
\n"); printf ("
\n"); - +*/ babl_destroy (); return 0; diff --git a/tests/babl_fish_path_dhtml.c b/tests/babl_fish_path_dhtml.c new file mode 100644 index 0000000..7694914 --- /dev/null +++ b/tests/babl_fish_path_dhtml.c @@ -0,0 +1,328 @@ +/* perform a symmetricality of conversion test on a set of randomized + * RGBA data */ + +#include +#include +#include "babl-internal.h" + +#define pixels 1024 +int total_length=0; +int total_cost=0; +int total = 0; +int ok = 0; + +static double test[pixels * 4]; + +static void +test_init (void) +{ + int i; + + for (i = 0; i < pixels * 4; i++) + test [i] = (double)random () / RAND_MAX; +} + +static int qux=0; + +static char *utf8_bar[]={" ","·","▁","▂","▃","▄","▅","▆","▇","█"}; +//static char *utf8_bar[]= {"!","▁","▃","▅","▇","█","!","!","!"}; +//static char *utf8_bar[]={"·", "█", "▇", "▆", "▅", "▄", "▃", "▂", "▁", }; +//static char *utf8_bar[]={" ","1","2","3","4","5","6","7","8"}; + +static int +table_destination_each (Babl *babl, + void *userdata) +{ + Babl *source = userdata; + Babl *destination = babl; + + if ((qux++) % babl_formats_count () == qux/ babl_formats_count ()) + printf (" "); + else + { + Babl *temp = babl_fish_path (source, destination); + + if (temp) + { + printf ("%s", + temp, temp, utf8_bar[temp->fish_path.conversions]); + total_length += temp->fish_path.conversions; + total_cost += temp->fish_path.cost; + ok ++; + total ++; + } + else + { + printf ("%s", + source, destination, + source, destination, + " "); + } + } + return 0; +} + +static int source_no=0; + +static int +table_source_each (Babl *babl, + void *userdata) +{ + char expanded_name[512]; + const char *s; + char *d; + + s=babl->instance.name; + d=&expanded_name[0]; + + while (*s) + { + switch (*s) + { + case ' ': + *(d++)='&'; + *(d++)='n'; + *(d++)='b'; + *(d++)='s'; + *(d++)='p'; + *(d++)=';'; + *(d) ='\0'; + s++; + break; + default: + *(d++)=*(s++); + *(d) ='\0'; + break; + } + } + + printf (""); + printf ("%s", + babl, babl, expanded_name); + babl_format_each (table_destination_each, babl); + printf ("\n"); + source_no++; + return 0; +} + + + +static int +detail_destination_each (Babl *babl, + void *userdata) +{ + Babl *source = userdata; + Babl *destination = babl; + + Babl *temp = babl_fish_path (source, destination); + + if (temp) + { + int i; + printf ("\n"); + } + else + { + printf ("\n"); + } + return 0; +} + +static int +detail_source_each (Babl *babl, + void *userdata) +{ + babl_format_each (detail_destination_each, babl); + return 0; +} + +static int +format_each (Babl *babl, + void *userdata) +{ + int i; + + printf ("\n"); + return 0; +} + + +int main (void) +{ + babl_init (); + test_init (); + + babl_set_extender (babl_extension_quiet_log ()); + + printf ( +"\n" +"\n" +"\n" +"\n" +"BablFishPath introspection\n" + + "" + +"" + + +"\n"); + + printf ( "\n"); + + printf ("

BablFishPath introspection

"); + printf ("

The table below represents many of the possible conversions available through babl, (the selection of formats includes all formats that shortcut conversions have been registered for.)

"); + printf ("

Hover your mouse over a formats name, or a non blank cell on the horizontal line to see further information

"); + + printf ("
/babl"); + printf ( "\n"); + babl_format_each (table_source_each, NULL); + printf ("
"); + + printf ("
"); + babl_format_each (detail_source_each, NULL); + babl_format_each (format_each, NULL); + printf ("
"); + + printf ("
\n"); + + printf ("\n"); + + babl_destroy (); + + return 0; +} diff --git a/tests/babl_fish_path_fitness.c b/tests/babl_fish_path_fitness.c new file mode 100644 index 0000000..2938f9d --- /dev/null +++ b/tests/babl_fish_path_fitness.c @@ -0,0 +1,95 @@ +/* perform a symmetricality of conversion test on a set of randomized + * RGBA data */ + +#include +#include +#include "babl-internal.h" + +#define pixels 1024 +int total_length=0; +int total_cost=0; +int total = 0; +int ok = 0; + +static double test[pixels * 4]; + +static void +test_init (void) +{ + int i; + + for (i = 0; i < pixels * 4; i++) + test [i] = (double)random () / RAND_MAX; +} + +static int qux=0; + +static char *utf8_bar[]={" ","·","▁","▂","▃","▄","▅","▆","▇","█"}; +//static char *utf8_bar[]= {"!","▁","▃","▅","▇","█","!","!","!"}; +//static char *utf8_bar[]={"·", "█", "▇", "▆", "▅", "▄", "▃", "▂", "▁", }; +//static char *utf8_bar[]={" ","1","2","3","4","5","6","7","8"}; + +static int destination_each (Babl *babl, + void *userdata) +{ + Babl *source = userdata; + Babl *destination = babl; + + if ((qux++) % babl_formats_count () == qux/ babl_formats_count ()) + printf (" "); + else + { + Babl *temp = babl_fish_path (source, destination); + + if (temp) + { + printf ("%s", utf8_bar[temp->fish_path.conversions]); + total_length += temp->fish_path.conversions; + total_cost += temp->fish_path.cost; + ok ++; + total ++; + } + else + { + printf (" "); + total ++; + } + } + return 0; +} + +static int source_no=0; + +static int source_each (Babl *babl, + void *userdata) +{ + babl_format_each (destination_each, babl); + printf ("──%2i %s\n", source_no++, babl->instance.name); + return 0; +} + +int main (void) +{ + babl_init (); + test_init (); + + babl_set_extender (babl_extension_quiet_log ()); + babl_format_each (source_each, NULL); + { + int i; + + for (i=0;i #include "babl-internal.h" -int OK=1; - -#define pixels 512 -#define TOLERANCE 0.001 - #define ERROR_TOLERANCE 0.5 -double test[pixels * 4]; - -static void -test_init (void) -{ - int i; - - for (i = 0; i < pixels * 4; i++) - test [i] = (double)random () / RAND_MAX; -} - -static void -validate_conversion (BablConversion *conversion) -{ - Babl *fmt_rgba_double; - Babl *fmt_source; - Babl *fmt_destination; - - double error=0.0; - - void *source; - void *destination; - double *destination_rgba_double; - void *ref_destination; - double *ref_destination_rgba_double; - - fmt_rgba_double = babl_format_new ( - babl_model ("RGBA"), - babl_type ("double"), - babl_component ("R"), - babl_component ("G"), - babl_component ("B"), - babl_component ("A"), - NULL); - fmt_source = BABL(conversion->source); - fmt_destination = BABL(conversion->destination); - - source = babl_calloc (pixels, fmt_source->format.bytes_per_pixel); - destination = babl_calloc (pixels, fmt_destination->format.bytes_per_pixel); - ref_destination = babl_calloc (pixels, fmt_destination->format.bytes_per_pixel); - destination_rgba_double = babl_calloc (pixels, fmt_rgba_double->format.bytes_per_pixel); - ref_destination_rgba_double = babl_calloc (pixels, fmt_rgba_double->format.bytes_per_pixel); - - babl_process (babl_fish_reference (fmt_rgba_double, fmt_source), - test, source, pixels); - babl_process (babl_fish_simple (conversion), - source, destination, pixels); - - babl_process (babl_fish_reference (fmt_source, fmt_destination), - source, ref_destination, pixels); - - babl_process (babl_fish_reference (fmt_destination, fmt_rgba_double), - ref_destination, ref_destination_rgba_double, pixels); - babl_process (babl_fish_reference (fmt_destination, fmt_rgba_double), - destination, destination_rgba_double, pixels); - - { - int i; - int cnt=0; - - for (i=0;iTOLERANCE) - log=1; - } - if (0 && log && cnt < 5) - { - /* enabling this code prints out the RGBA double values at various stages, - * which are used for the average relative error - */ - - babl_log ("%s", conversion->instance.name); - babl_log ("\ttest: %2.5f %2.5f %2.5f %2.5f", test [i*4+0], - test [i*4+1], - test [i*4+2], - test [i*4+3]); - babl_log ("\tconversion: %2.5f %2.5f %2.5f %2.5f", destination_rgba_double [i*4+0], - destination_rgba_double [i*4+1], - destination_rgba_double [i*4+2], - destination_rgba_double [i*4+3]); - babl_log ("\tref_conversion: %2.5f %2.5f %2.5f %2.5f", ref_destination_rgba_double [i*4+0], - ref_destination_rgba_double [i*4+1], - ref_destination_rgba_double [i*4+2], - ref_destination_rgba_double [i*4+3]); - cnt++; - OK=0; - } - } - error /= pixels; - error *= 100; - - conversion->error = error; - if (error >= ERROR_TOLERANCE) - { - babl_log ("%s\terror:%f", conversion->instance.name, error); - OK = 0; - } - } - - - babl_free (source); - babl_free (destination); - babl_free (destination_rgba_double); - babl_free (ref_destination); - babl_free (ref_destination_rgba_double); -} +static int OK=1; static int each_conversion (Babl *babl, void *userdata) { - Babl *source = BABL(babl->conversion.source); - Babl *destination = BABL(babl->conversion.destination); + double error = babl->conversion.error; - if (source->instance.id != BABL_RGBA && - destination->instance.id != BABL_RGBA && - source->instance.id != BABL_DOUBLE && - destination->instance.id != BABL_DOUBLE && - source->class_type == BABL_FORMAT && - destination->class_type == BABL_FORMAT) - { - validate_conversion ((BablConversion*)babl); - } + if (error >= ERROR_TOLERANCE) + { + babl_log ("%s\terror:%f", babl->instance.name, error); + OK = 0; + } return 0; } int main (void) { babl_init (); - test_init (); babl_set_extender (babl_extension_quiet_log ()); babl_conversion_each (each_conversion, NULL); diff --git a/tests/formats.c b/tests/formats.c index 721ccc5..abe0f89 100644 --- a/tests/formats.c +++ b/tests/formats.c @@ -5,81 +5,17 @@ #include #include "babl-internal.h" -#define pixels 1024 - -static double test[pixels * 4]; - -static void -test_init (void) -{ - int i; - - for (i = 0; i < pixels * 4; i++) - test [i] = (double)random () / RAND_MAX; -} int format_check (Babl *babl, void *userdata) { - void *original; - double *clipped; - void *destination; - double *transformed; - - Babl *ref_fmt; - Babl *fmt; - Babl *fish_to; - Babl *fish_from; - - ref_fmt = babl_format_new ( - babl_model ("RGBA"), - babl_type ("double"), - babl_component ("R"), - babl_component ("G"), - babl_component ("B"), - babl_component ("A"), - NULL); - - fmt = babl; - fish_to = babl_fish (ref_fmt, fmt); - fish_from = babl_fish (fmt, ref_fmt); - - original = babl_calloc (pixels, fmt->format.bytes_per_pixel); - clipped = babl_calloc (pixels, ref_fmt->format.bytes_per_pixel); - destination = babl_calloc (pixels, fmt->format.bytes_per_pixel); - transformed = babl_calloc (pixels, ref_fmt->format.bytes_per_pixel); - - babl_process (fish_to, test, original, pixels); - babl_process (fish_from, original, clipped, pixels); - babl_process (fish_to, clipped, destination, pixels); - babl_process (fish_from, destination, transformed, pixels); - - { - int i; - double loss=0.0; - - for (i=0;iinstance.name, loss); - babl->format.loss = loss; - } - - babl_free (original); - babl_free (clipped); - babl_free (destination); - babl_free (transformed); + babl_log ("%s\tloss: %f", babl->instance.name, babl->format.loss); return 0; } int main (void) { babl_init (); - test_init (); babl_set_extender (babl_extension_quiet_log ()); babl_format_each (format_check, (void*)1); diff --git a/tests/models.c b/tests/models.c index 9faf564..040664d 100644 --- a/tests/models.c +++ b/tests/models.c @@ -7,167 +7,22 @@ int OK=1; -#define pixels 1024 -#define TOLERANCE 0.001 - -double test[pixels * 4]; - -double r_interval (double min, double max) -{ - long int rand_i = random (); - double ret; - ret = (double) rand_i / RAND_MAX; - ret*=(max-min); - ret+=min; - return ret; -} - -void test_init (void) -{ - double r_min = -0.2, - r_max = 1.5, - g_min = -0.2, - g_max = 1.5, - b_min = -0.2, - b_max = 1.5, - a_min = -0.5, - a_max = 1.5; - int i; - double r,g,b,a; - for (i=0;imodel.components; i++) - { - argument[args++] = model->model.component[i]; - } - argument[args++] = NULL; - -#define o(argno) argument[argno], - return babl_format_new (o(0) o(1) o(2) o(3) - o(4) o(5) o(6) o(7) - o(8) o(9) o(10) o(11) - o(12) o(13) o(14) o(15) - o(16) o(17) o(18) o(19) - o(20) o(21) o(22) o(23) - o(24) o(25) o(26) o(27) - o(28) o(29) o(30) o(31) - o(32) o(33) o(34) o(35) - o(36) o(37) o(38) o(39) - o(40) o(41) o(42) NULL); -#undef o -} int model_check (Babl *babl, void *userdata) { - void *original; - double *clipped; - void *destination; - double *transformed; - - Babl *ref_fmt; - Babl *fmt; - Babl *fish_to; - Babl *fish_from; - - ref_fmt = reference_format (); - fmt = construct_double_format (babl); - fish_to = babl_fish (ref_fmt, fmt); - fish_from = babl_fish (fmt, ref_fmt); - - original = babl_calloc (1,64/8 * babl->model.components * pixels); - clipped = babl_calloc (1,64/8 * 4 * pixels); - destination = babl_calloc (1,64/8 * babl->model.components * pixels); - transformed = babl_calloc (1,64/8 * 4 * pixels); - - babl_process (fish_to, test, original, pixels); - babl_process (fish_from, original, clipped, pixels); - babl_process (fish_to, clipped, destination, pixels); - babl_process (fish_from, destination, transformed, pixels); - - { - int i; - int log=0; - - for (i=0;iTOLERANCE) - { - if (!log) - log=1; - OK=0; - } - if (log && log < 5) - { - babl_log ("%s", babl->instance.name); - babl_log ("\ttest: %2.3f %2.3f %2.3f %2.3f", test [i*4+0], - test [i*4+1], - test [i*4+2], - test [i*4+3]); - babl_log ("\tclipped: %2.3f %2.3f %2.3f %2.3f", clipped [i*4+0], - clipped [i*4+1], - clipped [i*4+2], - clipped [i*4+3]); - babl_log ("\ttrnsfrmd: %2.3f %2.3f %2.3f %2.3f", transformed [i*4+0], - transformed [i*4+1], - transformed [i*4+2], - transformed [i*4+3]); - log++; - OK=0; - } - } - } - - babl_free (original); - babl_free (clipped); - babl_free (destination); - babl_free (transformed); + if (!babl_model_is_symmetric (babl)) + { + babl_log ("%s is not symmetric", babl->instance.name); + OK=0; + } return 0; } + int main (void) { babl_init (); - test_init (); babl_set_extender (babl_extension_quiet_log ()); babl_model_each (model_check, NULL); diff --git a/tests/types.c b/tests/types.c index 5c71ad0..a0748b6 100644 --- a/tests/types.c +++ b/tests/types.c @@ -3,94 +3,14 @@ int OK=1; -#define TOLERANCE 0.000000001 -#define samples 2048 -double test[samples]; - -double r_interval (double min, double max) -{ - long int rand_i = random (); - double ret; - ret = (double) rand_i / RAND_MAX; - ret*=(max-min); - ret+=min; - return ret; -} - -void test_init (double min, double max) -{ - int i; - for (i=0;itype.bits/8 * samples); - clipped = babl_calloc (1,64/8 * samples); - destination = babl_calloc (1,babl->type.bits/8 * samples); - transformed = babl_calloc (1,64/8 * samples); - - babl_process (fish_to, test, original, samples); - babl_process (fish_from, original, clipped, samples); - babl_process (fish_to, clipped, destination, samples); - babl_process (fish_from, destination, transformed, samples); - - { - int cnt=0; - int i; - for (i=0;i TOLERANCE) - { - if (cnt++<4) - babl_log ("%s: %f %f %f)", - babl->instance.name, test[i], clipped[i], transformed[i] - ); - OK=0; - } - } - } - - babl_free (original); - babl_free (clipped); - babl_free (destination); - babl_free (transformed); + if (!babl_type_is_symmetric (babl)) + { + babl_log ("%s is not symmetric", babl->instance.name); + OK=0; + } return 0; } @@ -98,8 +18,6 @@ int main (void) { babl_init (); - test_init (0.0, 182.0); - babl_set_extender (babl_extension_quiet_log ()); babl_type_each (type_check, NULL); -- 2.30.2